import { defineConfig, loadEnv } from 'vite';
import createVitePlugins from './src/vite/plugins';
import path from 'path';
// https://vitejs.dev/config/
export default defineConfig(function (_a) {
    var mode = _a.mode, command = _a.command;
    var env = loadEnv(mode, process.cwd());
    var VITE_APP_ENV = env.VITE_APP_ENV;
    return {
        base: VITE_APP_ENV === "production" ? "/" : "/",
        plugins: createVitePlugins(env, command === "build"),
        // 将 src 替换成 @
        resolve: {
            alias: {
                // 配置别名
                '@': path.resolve(__dirname, 'src')
            }
        },
        server: {
            proxy: {
                // 带选项写法：http://localhost:5173/api/bar -> http://jsonplaceholder.typicode.com/bar
                '/api/baidu_sugrec': {
                    target: 'https://www.baidu.com/sugrec?&prod=pc&wd=',
                    changeOrigin: true,
                    rewrite: function (path) { return path.replace(/^\/api\/baidu_sugrec/, ''); }
                },
                '/dev-api': {
                    target: 'http://localhost:8080/',
                    changeOrigin: true,
                    rewrite: function (path) { return path.replace(/^\/dev-api/, ''); }
                }
            }
        },
        css: {
            // css预处理器
            preprocessorOptions: {
                scss: {
                    // 引入 mixin.scss 这样就可以在全局中使用 mixin.scss中预定义的变量了
                    // 给导入的路径最后加上 ;
                    additionalData: '@import "@/assets/styles/variables.module.scss";'
                }
            }
        }
    };
});
